package org.itboys.mobile.controller.site;

import org.itboys.commons.CommonConstants;
import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.mobile.entity.mongo.JoinInformation;
import org.itboys.mobile.service.mongo.site.JoinSiteInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 作者：zzq
 * 时间：2017/9/22
 * 描述：雄安加盟网_资讯
 */
@Controller
@RequestMapping("/join/site/information")
public class JoinSiteInformationController extends BaseController{
    @Autowired
    private JoinSiteInformationService informationService;
    @RequestMapping("/save")
    public void save(HttpServletRequest request,
                     HttpServletResponse response,
                     @RequestParam(value="businessId",required=true)Long businessId,
                     @RequestParam(value="type",required=true)Integer type,
                     @RequestParam(value="image",required=true)String image,
                     @RequestParam(value="title",required=true)String title,
                     @RequestParam(value="viceTitle",required=true)String viceTitle,
                     @RequestParam(value="content",required=true)String content){
        try {
            informationService.save(new JoinInformation(businessId,type,image,title,viceTitle,content));
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.SUCCESS_CODE, CommonConstants.SUCCESS));

        } catch (Exception e) {
            String msg = "";
            if (e.getClass().getSimpleName().equalsIgnoreCase("ErroException")) {
                msg = e.getMessage();
            } else {
                msg = CommonConstants.ERROMSG;
                logger.error("/join/site/information/save------" + e.getMessage());
            }
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE,msg));;
        }

    }
}
